<script >
import axios from 'axios';
import qs from 'qs';
import router from "@/router/index.js";
import { useRouter } from 'vue-router'
import { mapMutations } from 'vuex';
export default{
  data(){
        return {
        Username:'',
        Password:''
        }
},
    methods: {
       ...mapMutations(['updateName']),
       resign(){
        router.push({name : 'Resign'})
       },
       async handleSubmit() {
        console.log(this.Username);
        console.log(this.Password);
        // let param=qs.Stringify
      // 使用Axios发送POST请求到Flask的/test路由
      // http://26.188.105.114:5000/upload
      const response1=await axios.post('http://127.0.0.1:5000/login/', {
            username: this.Username,
            password: this.Password
      }
      )
      console.log('上传成功');
      console.log(response1);
      console.log(response1.data);

      if(response1.data.sta=="success"){
            alert("登录成功");
            this.updateName(response1.data.username);
            router.push({ name: 'resumeUpload' })
        }else if(response1.data.sta=="error"){
          alert("登录失败,密码错误");
        }else if(response1.data=="empty"){
          alert("账号不存在")
        }else{
          alert("error")
        }
      
    }
  }
}
</script>
<template>
  <div class="bg">
  <div class="container">
    <div class="row">
      <div class="col-md-8">
        <div class="font-left">
          <p>
            <h1>智能简历分析系统</h1>
          </p>
          <p>
            <h3>My dream is the starry sea, and you?</h3>
          </p>
        </div>
      </div>
      <div class="col-md-4">
        <div class="t1">
          <div class="dltop">

            <h1 class="text-center">欢迎登录</h1>

          </div>
          <div>
                                    <form>
                                        <div class="row">
                                          <div class="col-md-2">
                                            <p class="text-center font-denglu">
                                                账号
                                            </p>
                                          </div>
                                          <div class="col-md-9">
                                            <input type="text" v-model="Username" class="form-control" placeholder="请输入账号">
                                          </div>
                                        </div>

                                        <div class="row">
                                            <div class="col-md-2">
                                              <p class="text-center font-denglu">
                                                  密码
                                              </p>
                                            </div>
                                            <div class="col-md-9">
                                              <input type="password" v-model="Password" class="form-control" placeholder="请输入密码">
                                            </div>
                                        </div>

                                          <div class="row">
                                            <div class="col-md-2"></div>
                                            <div class="col-md-6">
                                                <!-- <label class="form-check-label"> -->
                                                  <input  class="form-check-input" type="checkbox" > Remember me
                                                <!-- </label> -->
                                              </div>
                                            </div>
                                          <div class="col-md-12 text-center btn">
                                                <button type="button" @click="handleSubmit" class="btn btn-primary col-md-3 btn-l">登录</button> 
                                                <button type="button" @click="resign" class="btn btn-primary col-md-3 btn-r">
                                                   注册
                                                </button>
                                          </div>                                       
                                      </form>
                                </div>

        </div>
      </div>
    </div>
  </div>
  </div>
</template>

<style scoped>
.bg{
  background-image: url(../../assets/images/2b29d1d0d8690b37173dcddfd091f75.jpg);
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
  width: 100%;
  height: 100%;
  position: fixed;
  left: 0;
  top: 0;
}
.t1{
  margin:100px 0 200px 0;
  height: 400px;
  border: 2px white;
  border-radius: 10%;
  background-color: rgba(255, 255, 255, 0.56);
  box-shadow: 10px 10px 10px 10px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(5px);
}
.font-left{
  color:white;
  text-align: center;
  margin:200px auto 200px auto;
}
.dltop{
  height: 120px;
  margin-top: 50px;
  margin-bottom: 10px;
}
.dltop h1{
  line-height: 120px;
}


 .font-denglu{
                line-height: 38px;
                /* font-size: larger; */
                font-weight: bolder;
            }
            form{
                padding-left: 20px;
            }
            .row{
                margin-bottom: 8px;
                margin-top: 5px;
            }
            .btn-l{
                margin-right: 30px;
                /* margin-left: 20px; */
            }
            .btn-r{
                margin-left: 30px;
            }
            .btn{
                margin-top: 5px;
            }
            a{
              color: white;
            }
</style>